﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Data.SqlClient;

namespace TextMIS
{
    public partial class frmRegister : Form
    {
        public frmRegister()
        {
            InitializeComponent();
        }
        public static string DoctorNum;
        public static string Username;
        SqlConnection conn;
        SqlCommand com;
        SqlDataAdapter da;

        private void frmRegister_Load(object sender, EventArgs e)
        {
            conn = new SqlConnection(frmLogin.SQLstr);
        }

        private void btnUserRepeat_Click(object sender, EventArgs e)
        {
            txtUserName.Clear();
            txtUserPwd.Clear();
            txtRePwd.Clear();
        }

        private void btnUserOk_Click(object sender, EventArgs e)
        {

            if (txtUserPwd.Text == txtRePwd.Text)
            {
                com = new SqlCommand("insert into UserInfo(UserName,UserPassword,UserRight)values('" + txtUserName.Text.Trim() +
    "','" + txtUserPwd.Text.Trim() + "','普通用户')", conn);



                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                com.ExecuteNonQuery();
                conn.Close();
                Username = txtUserName.Text.ToString();
                MessageBox.Show("恭喜你！注册成功！");
                com = new SqlCommand("insert into PatientInfo(Username)values('" + txtUserName.Text.Trim() +"')", conn);



                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }

                com.ExecuteNonQuery();
                conn.Close();
            }
            else
            { MessageBox.Show("两次输入密码有误!"); }
        }

        private void btnUserReturn_Click(object sender, EventArgs e)
        {
            this.Close();
            this.DialogResult = DialogResult.OK; ;
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            da = new SqlDataAdapter("select * from JobNumInfo where JobNum = '" + txtNum.Text.Trim() + "'", conn);
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            da.Fill(ds, "JobNumInfo");
            if (ds.Tables["JobNumInfo"].Rows.Count > 0)
            {
                DoctorNum = txtNum.Text.ToString();
                frmDoctorRegis frmdr = new frmDoctorRegis();

                this.Hide();
                if (frmdr.ShowDialog() == DialogResult.OK)
                {
                    this.Show();
                }
                frmdr.Show();

            }
        }

        private void btnReturn_Click(object sender, EventArgs e)
        {
            txtNum.Clear();
        }

    }
}
